import {Component, OnInit} from '@angular/core';
import {GameApi, JoinGameReq} from "../../../api/GameApi";
import {ActivatedRoute, Router} from "@angular/router";

@Component({
  selector: 'app-join-game',
  templateUrl: './join-game.component.html',
  styleUrls: ['./join-game.component.scss']
})
export class JoinGameComponent implements OnInit {
  joinHouseCode: number | undefined

  constructor(private route: ActivatedRoute,
              private router: Router) {

  }



  ngOnInit(): void {
  }

  async joinHouse() {


    const joinGameRespResult = await GameApi.Join(new JoinGameReq(this.joinHouseCode!));
    if (joinGameRespResult.success()) {
     await this.router.navigate(['../house',this.joinHouseCode], {relativeTo: this.route});

    } else {
      joinGameRespResult.resolveError(this.router,this.route)
    }
  }
}
